import React from 'react';
import { Table, message } from 'antd';
import Api from 'Utils/api';
import moment from 'moment';
import './index.scss';

const PAGE_SIZE = 10;
class PatrolRecordPage extends React.PureComponent {
  constructor(props) {
    super(props);
    this.state = {
      id: props.params.id,
      data: [],
      dataCount: 0,
      currentPage: 1,
      pageSise: PAGE_SIZE
    };
    this.initCheck = ::this.initCheck;
  }
  componentWillMount() {
    this.initCheck();
  }
  //巡查记录
  initCheck() {
    const { currentPage, pageSise } = this.state;
    const api = new Api({
      method: 'GET',
      path: `/enterprise_details/yong_an_tong_check/${this.state.id}`,
      query: {
        offset: (currentPage - 1) * pageSise,
        limit: pageSise
      },
      success: (res) => {
        console.log(res);
        this.setState({
          data: res.data_list,
          dataCount: res.total_count
        });
      },
      error: (msg) => {
        message.error(msg);
      }
    });
    api.run();
  }
  generatorColumns() {
    return [
      {
        title: '时间',
        dataIndex: 'upload_date',
        render: text => (
          <span>{moment(text).format('YYYY/MM/DD')}</span>
        )
      },
      {
        title: '结果',
        dataIndex: 'name',
        render: text => (
          <span >{text}</span >
        )
      },
    ];
  }
  onListPageChange(page) {
    this.setState({ currentPage: page }, () => { this.initCheck(); });
  }
  render() {
    const columns = this.generatorColumns();
    return (
      <div className="content-wrapper" >
        <div className="main-container">
          <Table
            rowKey={record => record.id}
            columns={columns}
            bordered
            dataSource={this.state.data}
            pagination={{
              pageSize: this.state.pageSise,
              total: this.state.dataCount,
              current: this.state.currentPage,
              onChange: this.onListPageChange.bind(this)
            }}
          />
        </div>
      </div>
    );
  }
}

export default PatrolRecordPage;
